using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using RetailAnalytic.Core;

namespace RetailAnalytic.Tools.SaveLocalCube
{
    public partial class UcMembers : UserControl
    {
        bool lev = false;
        bool child = false;
        public FrmLocalCube _parF;
        public UcMembers(FrmLocalCube parForm)
        {
            InitializeComponent();
            _parF = parForm;
        }

        private void utMembers_AfterCheck(object sender, Infragistics.Win.UltraWinTree.NodeEventArgs e)
        {
            if (e.TreeNode.Level == 0)
            {
                if (!child)
                {
                    lev = true;
                    if (e.TreeNode.CheckedState == CheckState.Checked)
                    {
                        for (int i = 0; i <= e.TreeNode.Nodes.Count - 1; i++)
                        {
                            e.TreeNode.Nodes[i].CheckedState = CheckState.Checked;
                        }
                    }
                    else
                    {
                        for (int i = 0; i <= e.TreeNode.Nodes.Count - 1; i++)
                        {
                            e.TreeNode.Nodes[i].CheckedState = CheckState.Unchecked;
                        }
                    }
                    lev = false;
                }
            }
            else
            {
                child = true;
                if (!lev)
                {
                    bool ck = false;
                    if (e.TreeNode.CheckedState == CheckState.Checked)
                    {
                        for (int i = 0; i <= e.TreeNode.Parent.Nodes.Count - 1; i++)
                        {
                            if (e.TreeNode.Parent.Nodes[i] != e.TreeNode)
                            {
                                if (e.TreeNode.Parent.Nodes[i].CheckedState == CheckState.Unchecked)
                                {
                                    ck = true;
                                }
                            }
                        }
                        if (ck) { e.TreeNode.Parent.CheckedState = CheckState.Indeterminate; }
                        else { e.TreeNode.Parent.CheckedState = CheckState.Checked; }
                        e.TreeNode.CheckedState = CheckState.Checked;
                    }
                    else
                    {
                        for (int i = 0; i <= e.TreeNode.Parent.Nodes.Count - 1; i++)
                        {
                            if (e.TreeNode.Parent.Nodes[i] != e.TreeNode)
                            {
                                if (e.TreeNode.Parent.Nodes[i].CheckedState == CheckState.Checked)
                                {
                                    ck = true;
                                }
                            }
                        }
                        if (ck) { e.TreeNode.Parent.CheckedState = CheckState.Indeterminate; }
                        else { e.TreeNode.Parent.CheckedState = CheckState.Unchecked; }
                        e.TreeNode.CheckedState = CheckState.Unchecked;
                    }
                }
                child = false;
            }
        }
    }
}
